﻿using CcrFlows.Core;
using CcrFlows.Stages;
using Microsoft.Ccr.Core;

namespace CcrFlows.Internal.Stages
{
    class ScatterStage<TIn, TOut> : IteratorStage<TIn, TOut>
    {
        internal ScatterStage(SeqHandler<TIn, TOut> handler)
        {
            base.InitializeInputHandler(Arbiter.Receive(
                                        true,
                                        (Port<TIn>)base.inputPorts[0],
                                        i => handler(i, (Port<TOut>)base.outputPorts[0])));
        }

        
        internal ScatterStage(SeqIteratorHandler<TIn, TOut> handler)
        {
            base.InitializeInputHandler(Arbiter.Receive(
                                            true,
                                            (Port<TIn>) base.inputPorts[0],
                                            i => base.ProcessIteratorHandler(i, handler, false)));
        }
    }
}
